package com.ewing.graphqltest.service;

import com.ewing.graphqltest.dao.UserJpaRepository;
import com.ewing.graphqltest.dao.VideoJpaRepository;
import com.ewing.graphqltest.model.UserEntity;
import com.ewing.graphqltest.model.VideoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class VideoService {
    @Autowired
    private VideoJpaRepository videoJpaRepository;

    public List<VideoEntity> findAll(){
        return videoJpaRepository.findAll();
    }

    public List<VideoEntity> findByUserId(Integer userId){
        VideoEntity videoEntity = new VideoEntity();
        videoEntity.setDouyin_user_id(userId);
        Example<VideoEntity> example = Example.of(videoEntity);
        return videoJpaRepository.findAll(example);
    }
}
